import { createRouter, createWebHistory } from 'vue-router'
<<<<<<< HEAD
// 导入起始页面组件
import Start from '@/views/Start/Start.vue';
// 导入首页组件
import Home from '@/views/Home/Home.vue'
// 导入医生列表页面组件
import Aone from '@/views/Aone/Aone.vue';
// 导入评论列表页面组件
import Comments from '@/views/Comments/Comments.vue';
// 导入咨询页面组件
import Counseling from '@/views/Counseling/Counseling.vue';
//医生详情
import Wdoctor from '@/views/Wdoctor/Wdoctor.vue';
//404页面
import NotFound from '@/views/NotFound/NotFound.vue'
import Classify from '@/views/Classify/Classify.vue'
//帮助
import Help from '@/views/Help/Help.vue'
//帮助详情页面
import Helpxx from '@/views/Helpxx/Helpxx.vue'
//病友圈
import Wardcircle from '@/views/Wardcircle/Wardcircle.vue'
//视频
import Videosr from '@/views/Videosr/Videosr.vue'
//编辑
import Copyreader from '@/views/Copyreader/Copyreader.vue'
//编辑
=======
// import HomeView from '../views/HomeView.vue' // 注意：这里可能是一个错误，因为你没有在路由中使用 HomeView，而是使用了其他组件  

>>>>>>> lsh1
// 模拟检查用户是否登录的方法  
function isAuthenticated() {
  // 从localStorage中获取token并判断其是否存在  
  return !!localStorage.getItem('token');
}
console.log(isAuthenticated());


const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
<<<<<<< HEAD
      path: '/Start',
      name: 'Start',
      redirect: '/Start'
    },
    {
      path: '/',
      name: 'Start',
      component: Start
=======
      path: '/',
      redirect: '/login' // 默认重定向到登录页面  
    },
    {
      path: '/home',
      name: 'home',
      component: () => import('../views/Home/Index.vue')
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('../views/Login/Index.vue')
>>>>>>> lsh1
    },
    {
      path: '/forgot',
      name: 'forgot',
      component: () => import('../views/Login/Forgot.vue')
    },
    {
<<<<<<< HEAD
      path: '/Home',
      name: 'Home',
      component: Home
    },
    {
      path: '/Comments',
      name: 'Comments',
      component: Comments
=======
      path: '/register',
      name: 'register',
      component: () => import('../views/Login/Register.vue')
>>>>>>> lsh1
    },
    {
      path: '/password',
      name: 'password',
      component: () => import('../views/Login/Password.vue')
    },
    //消息
    {
<<<<<<< HEAD
      path: '/Wdoctor',
      name: 'Wdoctor',
      component: Wdoctor
    },
    {
      path: '/Classify',
      name: 'Classify',
      component: Classify
    },
    {
      path: '/Help',
      name: 'Help',
      component: Help
    },
    {
      path: '/Helpxx',
      name: 'Helpxx',
      component: Helpxx
    },
    {
      path: '/Wardcircle',
      name: 'Wardcircle',
      component: Wardcircle
    },
    {
      path: '/Videosr',
      name: 'Videosr',
      component: Videosr
    },
    {
      path: '/Copyreader',
      name: 'Copyreader',
      component: Copyreader
    },
    {
      path: '/:pathMatch(.*)*',
      name: 'NotFound',
      component: NotFound
    },
    {
      path: '/about',
      name: 'about',
     component: () => import('../views/AboutView.vue')
    },

     {
      path: '/shou',
      name: '首页',
     component: () => import('../views/shou/Shou.vue')
    },
    {
      path: '/details',
      name: '详情',
     component: () => import('../views/details/Details.vue')
    },
    {
       path: '/my',
      name: '我的',
     component: () => import('../views/My/My.vue')
    },
    {
      path: '/shi',
      name: '实验路由',
     component: () => import('../views/Shi.vue')
    },
     {
      path: '/video',
      name: '视频',
     component: () => import('../views/Video/Video.vue')
    },
    {
      path: '/video',
      name: '视频',
     component: () => import('../views/Video/Video.vue')
    },
     {
=======
>>>>>>> lsh1
      path: '/message',
      name: 'message',
      component: () => import('../views/Message/Index.vue')
    },
    {
      path: '/system',
      name: 'system',
      component: () => import('../views/Message/System.vue')
    },
    {
      path: '/consultation',
      name: 'consultation',
      component: () => import('../views/Message/Consultation.vue')
    },
    {
      path: '/hcoinreceipt',
      name: 'hcoinreceipt',
      component: () => import('../views/Message/Hcoinreceipt.vue')
    },
    {
      path: '/wallet',
      name: 'wallet',
      component: () => import('../views/Wallet/Index.vue')
    },
    {
      path: '/recharge',
      name: 'recharge',
      component: () => import('../views/Wallet/Recharge.vue')
    },
    {
      path: '/withdrawal',
      name: 'withdrawal',
      component: () => import('../views/Wallet/Withdrawal.vue')
    },
    {
      path: '/withprocess',
      name: 'withprocess',
      component: () => import('../views/Wallet/Withprocess.vue')
    }, 
    {
      path: '/withdrecord',
      name: 'withdrecord',
      component: () => import('../views/Wallet/Withdrecord.vue')
    }
  ]
});
// 全局前置守卫  
router.beforeEach((to, from, next) => {
  // 定义哪些路由需要认证  
  const requiresAuth = ['/home', '/message', '/system', '/consultation', '/hcoinreceipt', '/wallet', '/recharge', '/withdrawal', '/withprocess'].includes(to.path);

  if (requiresAuth) {
    // 检查用户是否已登录  
    if (isAuthenticated()) {
      // 用户已登录，继续到目标路由  
      next();
    } else {
      // 用户未登录，重定向到登录页面  
      next({ path: '/login' })
    }
  } else {
    // 路由不需要认证，直接通过  
    next();
  }
  console.log(requiresAuth);
});


export default router;